package at.fhj.itm11.forum.beans.stubs;

import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import javax.faces.application.Application;
import javax.faces.application.FacesMessage;
import javax.faces.application.FacesMessage.Severity;
import javax.faces.component.UIViewRoot;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseStream;
import javax.faces.context.ResponseWriter;
import javax.faces.event.PhaseId;
import javax.faces.render.RenderKit;

public class FacesContextStub extends FacesContext {

	private ExternalContextStub externalContext = new ExternalContextStub();
	private PhaseId phaseId;
	
	private Map<String, FacesMessage> messages;

	@Override
	public PhaseId getCurrentPhaseId() {
		return phaseId;
	}

	@Override
	public Application getApplication() {

		return null;
	}

	@Override
	public Iterator<String> getClientIdsWithMessages() {

		return null;
	}

	@Override
	public ExternalContext getExternalContext() {
		return externalContext;
	}

	@Override
	public Severity getMaximumSeverity() {

		return null;
	}

	@Override
	public Iterator<FacesMessage> getMessages() {
		return null;
	}

	@Override
	public Iterator<FacesMessage> getMessages(String clientId) {
		if (messages != null) {
			FacesMessage msg = messages.get(clientId);

			if (msg != null) {
				List<FacesMessage> list = new LinkedList<FacesMessage>();
				list.add(msg);
				return list.iterator();
			}
		}
		
		return null;
	}

	@Override
	public RenderKit getRenderKit() {

		return null;
	}

	@Override
	public boolean getRenderResponse() {

		return false;
	}

	@Override
	public boolean getResponseComplete() {

		return false;
	}

	@Override
	public ResponseStream getResponseStream() {

		return null;
	}

	@Override
	public void setResponseStream(ResponseStream responseStream) {

	}

	@Override
	public ResponseWriter getResponseWriter() {

		return null;
	}

	@Override
	public void setResponseWriter(ResponseWriter responseWriter) {

	}

	@Override
	public UIViewRoot getViewRoot() {

		return null;
	}

	@Override
	public void setViewRoot(UIViewRoot root) {

	}

	@Override
	public void addMessage(String clientId, FacesMessage message) {
		if(messages == null) {
			messages = new HashMap<String, FacesMessage>();
		}
		
		messages.put(clientId, message);
	}

	@Override
	public void release() {

	}

	@Override
	public void renderResponse() {

	}

	@Override
	public void responseComplete() {

	}

	public PhaseId getPhaseId() {
		return phaseId;
	}

	public void setPhaseId(PhaseId phaseId) {
		this.phaseId = phaseId;
	}

}
